﻿/***************************************************************
* File    : RpmSensor.cs
* Author  : Matthew Clifton
*
* Description:
*   RPM Sensor object. Extends Sensor
*
* History :
***************************************************************/

using System;
namespace RLGDashboard
{
    public class RpmSensor : Sensor
    {
        int RPM_SENSORS = 3;
        UInt16[] pulseCount = new UInt16[4];
        UInt16[] pulseRate = new UInt16[4];

        public override object[] convert(UInt16[] inValues)
        {
            object[] convertedValues = new object[4];

            for (int i = 0; i < RPM_SENSORS; i++)
            {
                if (pulseRate[i] != 0)
                {
                    convertedValues[i] = (Int16)(pulseCount[i] / pulseRate[i]);
                }
                else
                {
                    convertedValues[i] = 0;
                }
            }
            return convertedValues;
        }
        /*
        public override string[] getValues()
        {
            string[] values = new string[4];
            int i = 0;

            foreach (object temp in currentSensorValues)
            {
                if (temp != null)
                {
                    values[i] = temp.ToString() + " RPM";
                    i++;
                }
            }

            updated = false;
            return values;
        }*/

        public void updatePulseRate(BluetoothTransmission transmission)
        {
            pulseRate = transmission.sensors;
            updateValues(transmission);
        }

        public void updatePulseCount(BluetoothTransmission transmission)
        {
            pulseCount = transmission.sensors;
            updateValues(transmission);
        }
    }
}